package com.xiaomo.gitee.datamanager.config;

import com.xiaomo.gitee.datamanager.util.JwtUtils;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//@EnableKnife4j
public class SwaggerConfig {

    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .components(new Components()
                        .addSecuritySchemes(JwtUtils.TOKEN_HEADER, new SecurityScheme()
                                .type(SecurityScheme.Type.HTTP)
                                .bearerFormat("JWT")
                                .scheme("bearer")))
                .info(new Info()
                        .title("数据管理API页面")
                        .description("前端API参考文档,登出 /logout")
                        .version("v2.5.0")
                        .license(new License()
                                .name("Apache 2.0")
                                .url("https://www.apache.org/licenses/LICENSE-2.0.html"))
                        .contact(new Contact()
                                .name("朱奕萌")
                                .email("1934944134@qq.com")));

    }

    @Bean
    public GroupedOpenApi publicApi(){
        return GroupedOpenApi.builder()
                .group("public")
                .pathsToMatch("/api/**")
                .displayName("普通用户API列表")
                .build();
    }

    @Bean
    public GroupedOpenApi adminApi() {
        return GroupedOpenApi.builder()
                .group("admin")
                .pathsToMatch("/admin/api/**","/user")
                .displayName("管理员API列表")
                .build();
    }

    @Bean
    public GroupedOpenApi security() {
        return GroupedOpenApi.builder()
                .group("security")
                .pathsToMatch("/login-api","/register","/perms")
                .displayName("账户安全API列表")
                .build();
    }

    @Bean
    public GroupedOpenApi all() {
        return GroupedOpenApi.builder()
                .group("all")
                .pathsToMatch("/**")
                .displayName("所有api")
                .build();
    }
}
